package com.ddsso.auth.web.vo;

import org.omg.CORBA.portable.ApplicationException;

/**
 * @author zdd
 * @package com.ddsso.auth.web.vo
 * @Time Created by zdd on 2016/11/2.
 * @description To-do
 */
public enum AuthResponseCode implements IErrors<AuthResponse>{
    /**
     * --- 以下是通用全局响应码
     */
    SUCCESS(0, "成功"),

    SYSTEM_ERROR(1, "系统出错了"),

    NOT_LOGIN(2, "您未登录或您的会话已过期, 请重新登录"),

    LOGIN_NAME_NOT_EXIST(3, "您的登录名不存在"),

    LOGIN_USER_FORBIDDEN(4, "您的帐户被禁用"),

    LOGIN_PASSWORD_NOT_CORRECT(5, "您的登录密码不正确"),

    INPUT_VALUE_EMPTY(6, "%s不能为空"),

    AUTHENTICATION_FAIL(7, "OMS用户认证失败:%s"),

    NOT_PERMISSION(8, "权限不足"),

    /**
     * --- 以下是OMS业务响应码
     */
    /**
     * 角色名称已存在
     */
    ROLE_NAME_REPETITION(25001, "%s"),

    ACCOUNT_IS_NOT_UNFREEZE(25002, "%s状态不是冻结"),

    // 会员状态不正确
    UPDATE_STATUS_NOT_CORRECT(20001, "%s"),

    // 账户状态
    /**
     * 冻结人和解冻人必须一致
     */
    ACOUNT_FROZEN_OPID_SAME_UNFROZEN_OPID(21000, "冻结人和解冻人必须一致"),

    /**
     * 账户余额冻结记录不存在
     */
    ACCOUNT_BALANCE_FROZEN_NOT_EXIST(21001, "账户【%s】余额冻结记录不存在"),

    /**
     * 账户不存在
     */
    ACCOUNT_NOT_EXIST(21002, "账户【%s】不存在"),

    /**
     * 账户处于冻结状态
     */
    ACCOUNT_IS_FROZEN(21003, "账户【%s】处于冻结状态"),

    /**
     * 解冻金额不合法
     */
    UNFROZENAMOUNT_IS_ILLEGAL(21004, "解冻金额不合法"),

    /**
     * 账户冻结记录不存在
     */
    ACOUNT_FROZEN_NOT_EXIST(21005, "账户【%s】冻结记录不存在"),

    /**
     * 对账明细记录不存在
     */
    RCON_DETAIL_NOT_EXIST(21006, "该记录已被审核，请刷新页面"),

    RECNO_DETAIL_IS_CHANGED(24601, "差异明细已被其他用户预处理了");

    private int code;

    private String message;

    private AuthResponseCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    @Override
    public AuthResponse parse() {
        AuthResponse result = new AuthResponse();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    @Override
    public AuthResponse parse(Object... args) {
        AuthResponse result = new AuthResponse();
        result.setCode(code);
        String formatReason = String.format(message, args);
        result.setMessage(formatReason);
        return result;
    }

    @Override
    public AuthResponse parseMsg(String message, Object... args) {
        this.message = message;
        return parse(args);
    }

    @Override
    public ApplicationException exp() {
        // nothing to do
        return null;
    }

    @Override
    public ApplicationException exp(Object... args) {
        // nothing to do
        return null;
    }

    @Override
    public ApplicationException expMsg(String message, Object... args) {
        // nothing to do
        return null;
    }

    @Override
    public ApplicationException exp(Throwable cause, Object... args) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ApplicationException expMsg(String message, Throwable cause, Object... args) {
        // TODO Auto-generated method stub
        return null;
    }
}
